//
//  BaseTabbarViewController.m
//  QA
//
//  Created by Yoga on 2017/4/19.
//  Copyright © 2017年 ZDQK. All rights reserved.
//

#import "BaseTabbarViewController.h"
#import "BaseNavigationViewController.h"

@interface BaseTabbarViewController ()<UITabBarControllerDelegate>

@property (nonatomic, strong) BaseNavigationViewController *first;
@property (nonatomic, strong) BaseNavigationViewController *second;
@property (nonatomic, strong) BaseNavigationViewController *third;
@property (nonatomic, strong) BaseNavigationViewController *fourth;

@end

@implementation BaseTabbarViewController

- (instancetype)init {
    self = [super init];
    if (self) {

    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initViewControllers];
}
//- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
//    if (item == self.tabBar.items.lastObject) {        
//        dispatch_async(dispatch_get_main_queue(), ^{
//            [self.tabBar hideBadgeOnItemIndex:4];
//        });
//    }
//}
#pragma mark - method
- (void)initViewControllers {
    self.delegate = self;
    self.viewControllers = @[self.first, self.second ,self.third, self.fourth];
    self.selectedIndex = 0;
    
    [UITabBar appearance].translucent = NO;
    [[UITabBar appearance] setBarTintColor:[UIColor colorWithHex:0xFEFEFE alpha:1.0]];
}
#pragma mark - getters
- (BaseNavigationViewController *)first {
    if (!_first) {
        _homeViewController = [[HomeViewController alloc] init];
        
        _first = [[BaseNavigationViewController alloc] initWithRootViewController:_homeViewController];
        
        _first.tabBarItem.title = @"首页";
        [_first.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
        [_first.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateSelected];
        _first.tabBarItem.image = [[UIImage imageNamed:@"home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        _first.tabBarItem.selectedImage = [[UIImage imageNamed:@"home_y"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    return _first;
}

- (BaseNavigationViewController *)second {
    if (!_second) {
        _classifyViewController = [[ClassifyListViewController alloc] init];
//        _classifyViewController = [[ClassListViewController alloc]init];
        
        _second = [[BaseNavigationViewController alloc] initWithRootViewController:_classifyViewController];
        
        _second.tabBarItem.title = @"分类";
        [_second.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
        [_second.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateSelected];
        _second.tabBarItem.image = [[UIImage imageNamed:@"class"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        _second.tabBarItem.selectedImage = [[UIImage imageNamed:@"class_y"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    return _second;
}

- (BaseNavigationViewController *)third {
    if (!_third) {
        _shoppingViewController = [[ShoppingCartHomeViewController alloc] init];
        
        _third = [[BaseNavigationViewController alloc] initWithRootViewController:_shoppingViewController];
        _third.tabBarItem.title = @"购物车";
        
        [_third.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
        [_third.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateSelected];
        _third.tabBarItem.image = [[UIImage imageNamed:@"bit"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        _third.tabBarItem.selectedImage = [[UIImage imageNamed:@"bit_y"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    return _third;
}

- (BaseNavigationViewController *)fourth {
    if (!_fourth) {
        _mineViewController = [[MineHomeViewController alloc] init];
        
        _fourth = [[BaseNavigationViewController alloc] initWithRootViewController:_mineViewController];
        _fourth.tabBarItem.title = @"我的";
        
        [_fourth.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
        [_fourth.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateSelected];
        _fourth.tabBarItem.image = [[UIImage imageNamed:@"mine"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        _fourth.tabBarItem.selectedImage = [[UIImage imageNamed:@"mine_y"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    return _fourth;
}


@end
